home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / rxasyn20.zip / RXSCRIPT.ZIP / MDMRESET.CMD < prev    next >
OS/2 REXX Batch file  |  1994-11-22  |  10KB  |  371 lines

  1. /*****************************************************************************/
  2.  
  3. call on error
  4.  
  5. /*--------------------------------------------------------------*/
  6. /* NOTE: Adjust the following as required by your configuration */
  7. /*       If you do NOT have a 16550 UART then set newFlags3     */
  8. /*       to '00000010'. (see the RXASYNC.c & .h for more info.) */
  9. /*--------------------------------------------------------------*/
  10.  
  11. PortName      = 'COM4'
  12. newBaud       = 19200
  13. newData       = 8
  14. newParity     = 'N'
  15. newStop       = 1
  16. newWriteLim   = 50
  17. newReadLim    = 50
  18. newFlags1     = '00001001'
  19. newFlags2     = '10100000'
  20. newFlags3     = '11010010'
  21. newErrChar    = '00'
  22. newBrkChar    = '00'
  23. newXonChar    = '11'
  24. newXoffChar   = '13'
  25. newEnhParms   = '00000010'
  26.  
  27. /*--------------------------------------------------------------*/
  28.  
  29. PortHandle    = ''
  30. old.Baud      = 0
  31. old.Data      = 0
  32. old.Parity    = ''
  33. old.Stop      = 0
  34. old.WriteLim  = 0
  35. old.ReadLim   = 0
  36. old.Flags1    = ''
  37. old.Flags2    = ''
  38. old.Flags3    = ''
  39. old.ErrChar   = ''
  40. old.BrkChar   = ''
  41. old.XonChar   = ''
  42. old.XoffChar  = ''
  43. old.EnhParms  = ''
  44.  
  45.  
  46. True          = 1
  47. False         = 0
  48. Regular       = 2
  49. Critical      = 3
  50. NormalLvl     = 0
  51. InpStr        = ''
  52. Remaining     = 0
  53. crlf          = D2C(13)''D2C(10)
  54. none_on       = '00'
  55. dtr_on        = '01'
  56. rts_on        = '02'
  57. both_on       = '03'
  58. none_off      = 'FF'
  59. dtr_off       = 'FE'
  60. rts_off       = 'FD'
  61. both_off      = 'FC'
  62.  
  63. /*--------------------------------------------------------------*/
  64.  
  65. /*-----------------------------*/
  66. /* Setup                       */
  67. /*-----------------------------*/
  68.  
  69. /* load functions */
  70.  
  71. call RxFuncAdd 'RxAsyncLoadFuncs', 'RXASYNC', 'RxAsyncLoadFuncs'
  72.  
  73. Say 'Modem Reset in progress'
  74.  
  75. rc = RxAsyncLoadFuncs()
  76. if rc <> 0 then do
  77.    say 'RxAsyncLoadFuncs failed with rc=>'rc'<'
  78.    exit
  79. end
  80.  
  81. /* set session priority */
  82.  
  83. rc = RxAsyncPriority( Critical, NormalLvl )
  84. if rc <> 0 then say 'RxAsyncPriority failed with rc=>'rc'<'
  85.  
  86. /* open device */
  87.  
  88. rc = RxAsyncOpen( PortName, 'PortHandle' )
  89. if rc <> 0 then say 'RxAsyncOpen failed with rc=>'rc'<'
  90.  
  91. say 'Port >'PortName'<'
  92.  
  93. /*-----------------------*/
  94. /* Line Control Handling */
  95. /*-----------------------*/
  96.  
  97. /* save original line control settings */
  98.  
  99. rc = RxAsyncGetLnCtrl( PortHandle, 'old.Baud', 'old.Data', 'old.Parity', 'old.Stop' )
  100. if rc <> 0 then say 'RxAsyncGetLnCtrl failed with rc=>'rc'<'
  101.  
  102. /* set new line control settings */
  103.  
  104. rc = RxAsyncSetLnCtrl( PortHandle, newBaud, newData, newParity, newStop )
  105. if rc <> 0 then say 'RxAsyncSetLnCtrl failed with rc=>'rc'<'
  106.  
  107. /* query new line control settings */
  108.  
  109. rc = RxAsyncGetLnCtrl( PortHandle, 'newBaud', 'newData', 'newParity', 'newStop' )
  110. if rc <> 0 then say 'RxAsyncGetLnCtrl failed with rc=>'rc'<'
  111.  
  112. say 'Baudrate >'newBaud'<'
  113. say 'Databits >'newData'<'
  114. say 'Parity   >'newParity'<'
  115. say 'Stopbits >'newStop'<'
  116.  
  117. /*-------------------------------*/
  118. /* Device Control Block Handling */
  119. /*-------------------------------*/
  120.  
  121. /* save original dcb info settings */
  122.  
  123. rc = RxAsyncGetDcbInfo( PortHandle, 'old.WriteLim', 'old.ReadLim', 'old.Flags1', 'old.Flags2', 'old.Flags3', 'old.ErrChar', 'old.BrkChar', 'old.XonChar', 'old.XoffChar' )
  124. if rc <> 0 then say 'RxAsyncGetDcbInfo failed with rc=>'rc'<'
  125.  
  126. old.Flags1 = X2B(old.Flags1)
  127. old.Flags2 = X2B(old.Flags2)
  128. old.Flags3 = X2B(old.Flags3)
  129.  
  130. /* set new dcb info settings */
  131.  
  132. rc = RxAsyncSetDcbInfo( PortHandle, newWriteLim, newReadLim, newFlags1, newFlags2, newFlags3, newErrChar, newBrkChar, newXonChar, newXoffChar )
  133. if rc <> 0 then say 'RxAsyncSetDcbInfo failed with rc=>'rc'<'
  134.  
  135. /* query new dcb info settings */
  136.  
  137. rc = RxAsyncGetDcbInfo( PortHandle, 'newWriteLim', 'newReadLim', 'newFlags1', 'newFlags2', 'newFlags3', 'newErrChar', 'newBrkChar', 'newXonChar', 'newXoffChar' )
  138. if rc <> 0 then say 'RxAsyncGetDcbInfo failed with rc=>'rc'<'
  139.  
  140. newFlags1 = X2B(newFlags1)
  141. newFlags2 = X2B(newFlags2)
  142. newFlags3 = X2B(newFlags3)
  143.  
  144. say 'Write Timeout  >'newWriteLim'<'
  145. say 'Read  Timeout  >'newReadLim'<'
  146. say 'F1 HandShake   >'newFlags1'<'
  147. say 'F2 FlowReplace >'newFlags2'<'
  148. say 'F3 Timeout     >'newFlags3'<'
  149. say 'Error Replace  >'newErrChar'<'
  150. say 'Break Replace  >'newBrkChar'<'
  151. say 'Xon character  >'newXonChar'<'
  152. say 'Xoff character >'newXoffChar'<'
  153.  
  154. /*-----------------------------*/
  155. /* Enhanced Parameter Handling */
  156. /*-----------------------------*/
  157.  
  158. /* save original enhanced parms settings */
  159.  
  160. rc = RxAsyncGetEnhParm( PortHandle, 'old.EnhParms' )
  161. if rc <> 0 then say 'RxAsyncGetEnhParm failed with rc=>'rc'<'
  162.  
  163. old.EnhParms = X2B(old.EnhParms)
  164.  
  165. /* set new enhanced parms settings */
  166.  
  167. rc = RxAsyncSetEnhParm( PortHandle, newEnhParms )
  168. if rc <> 0 then say 'RxAsyncSetEnhParm failed with rc=>'rc'<'
  169.  
  170. /* query new enhanced parms settings */
  171.  
  172. rc = RxAsyncGetEnhParm( PortHandle, 'newEnhParms' )
  173. if rc <> 0 then say 'RxAsyncGetEnhParm failed with rc=>'rc'<'
  174.  
  175. newEnhParms = X2B(newEnhParms)
  176.  
  177. say 'Enhanced Parms >'newEnhParms'<'
  178.  
  179. /*----------------------*/
  180. /* Read, Write and Wait */
  181. /*----------------------*/
  182.  
  183. /* write modem string */
  184.  
  185. rc = RxAsyncWrite( PortHandle, 0, 'ATT'||D2C(13), 'Remaining' )
  186. if rc <> 0
  187.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  188.    else say 'ATT<cr>'
  189.  
  190. /* read modem response */
  191.  
  192. InpStr = ""
  193. GetOk = True
  194. do while GetOk
  195.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  196.    GetOk = False
  197.    select
  198.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  199.      when InpStr == "OK"||crlf    then say '>'InpStr'<'
  200.      when InpStr == "ERROR"||crlf then say '>'InpStr'<'
  201.      otherwise
  202.         say '>'InpStr'<'
  203.         GetOk = True
  204.    end
  205. end
  206.  
  207. /* write modem string */
  208.  
  209. rc = RxAsyncWrite( PortHandle, 0, 'ATS0=0'||D2C(13), 'Remaining' )
  210. if rc <> 0
  211.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  212.    else say 'ATS0=0<cr>'
  213.  
  214. /* read modem response */
  215.  
  216. InpStr = ""
  217. GetOk = True
  218. do while GetOk
  219.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  220.    GetOk = False
  221.    select
  222.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  223.      when InpStr == "OK"||crlf    then say '>'InpStr'<'
  224.      when InpStr == "ERROR"||crlf then say '>'InpStr'<'
  225.      otherwise
  226.         say '>'InpStr'<'
  227.         GetOk = True
  228.    end
  229. end
  230.  
  231. /* write modem string */
  232.  
  233. rc = RxAsyncWrite( PortHandle, 0, 'ATB0E0F1L0M1Q0V1X6Y0'||D2C(13), 'Remaining' )
  234. if rc <> 0
  235.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  236.    else say 'ATB0E0F1L0M1Q0V1X6Y0<cr>'
  237.  
  238. /* read modem response */
  239.  
  240. InpStr = ""
  241. GetOk = True
  242. do while GetOk
  243.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  244.    GetOk = False
  245.    select
  246.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  247.      when InpStr == "OK"||crlf    then say '>'InpStr'<'
  248.      when InpStr == "ERROR"||crlf then say '>'InpStr'<'
  249.      otherwise
  250.         say '>'InpStr'<'
  251.         GetOk = True
  252.    end
  253. end
  254.  
  255. /* write modem string */
  256.  
  257. rc = RxAsyncWrite( PortHandle, 0, 'AT&B0&C1&D2&G0&P1&Q1&R1&S1$E1$F3$S8'||D2C(13), 'Remaining' )
  258. if rc <> 0
  259.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  260.    else say 'AT&B0&C1&D2&G0&P1&Q1&R1&S1$E1$F3$S8<cr>'
  261.  
  262. /* read modem response */
  263.  
  264. InpStr = ""
  265. GetOk = True
  266. do while GetOk
  267.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  268.    GetOk = False
  269.    select
  270.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  271.      when InpStr == "OK"||crlf    then say '>'InpStr'<'
  272.      when InpStr == "ERROR"||crlf then say '>'InpStr'<'
  273.      otherwise
  274.         say '>'InpStr'<'
  275.         GetOk = True
  276.    end
  277. end
  278.  
  279. /* write modem string */
  280.  
  281. rc = RxAsyncWrite( PortHandle, 0, 'AT&W0'||D2C(13), 'Remaining' )
  282. if rc <> 0
  283.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  284.    else say 'AT&W0<cr>'
  285.  
  286. /* read modem response */
  287.  
  288. InpStr = ""
  289. GetOk = True
  290. do while GetOk
  291.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  292.    GetOk = False
  293.    select
  294.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  295.      when InpStr == "OK"||crlf    then say '>'InpStr'<'
  296.      when InpStr == "ERROR"||crlf then say '>'InpStr'<'
  297.      otherwise
  298.         say '>'InpStr'<'
  299.         GetOk = True
  300.    end
  301. end
  302.  
  303. /* write modem string */
  304.  
  305. rc = RxAsyncWrite( PortHandle, 0, 'AT&W1'D2C(13), 'Remaining' )
  306. if rc <> 0
  307.    then say 'Modem may not be turned on, >'Remaining'< chars unwritten'
  308.    else say 'AT&W1<cr>'
  309.  
  310. /* read modem response */
  311.  
  312. InpStr = ""
  313. GetOk = True
  314. do while GetOk
  315.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  316.    GetOk = False
  317.    select
  318.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  319.      when InpStr == "OK"||crlf    then say '>'InpStr'<'
  320.      when InpStr == "ERROR"||crlf then say '>'InpStr'<'
  321.      otherwise
  322.         say '>'InpStr'<'
  323.         GetOk = True
  324.    end
  325. end
  326.  
  327. /*-----------------------------*/
  328. /* Cleanup                     */
  329. /*-----------------------------*/
  330.  
  331. /* reset to original enhanced parms settings */
  332.  
  333. rc = RxAsyncSetEnhParm( PortHandle, old.EnhParms )
  334. if rc <> 0 then say 'RxAsyncSetEnhParm failed with rc=>'rc'<'
  335.  
  336. /* reset to original dcb info settings */
  337.  
  338. rc = RxAsyncSetDcbInfo( PortHandle, old.WriteLim, old.ReadLim, old.Flags1, old.Flags2, old.Flags3, old.ErrChar, old.BrkChar, old.XonChar, old.XoffChar )
  339. if rc <> 0 then say 'RxAsyncSetDcbInfo failed with rc=>'rc'<'
  340.  
  341. /* reset to original line control settings */
  342.  
  343. rc = RxAsyncSetLnCtrl( PortHandle, old.Baud, old.Data, old.Parity, old.Stop )
  344. if rc <> 0 then say 'RxAsyncSetLnCtrl failed with rc=>'rc'<'
  345.  
  346. /* close the device */
  347.  
  348. rc = RxAsyncClose( PortHandle )
  349. if rc <> 0 then say 'RxAsyncClose failed with rc=>'rc'<'
  350.  
  351. /* reset session priority */
  352.  
  353. rc = RxAsyncPriority( Regular, NormalLvl )
  354. if rc <> 0 then say 'RxAsyncPriority failed with rc=>'rc'<'
  355.  
  356. /* drop functions */
  357.  
  358. rc = RxAsyncDropFuncs()
  359. if rc <> 0 then say 'RxAsyncDropFuncs failed with rc=>'rc'<'
  360.  
  361. Say 'Modem Reset is complete'
  362.  
  363. exit
  364.  
  365. /* just in case<g> */
  366.  
  367. error:
  368.    call RxAsyncClose PortHandle
  369.    exit
  370.  
  371.